package com.example.demo;

import com.yy.distributed.lock.redis.JedisDistributedLockTemplate;
import com.yy.distributed.lock.redis.JedisLockFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;

/**
 * Write your description here...
 *
 * @author dinghuan
 * @date 2018/7/20
 */
@Component
public class JedisLockConfig {

    @Autowired
    private JedisPool jedisPool;

    @Autowired
    private JedisLockFactory jedisLockFactory;

    @Bean(name = "jedisLockFactory")
    public JedisLockFactory getJedisTemplate() {
        return new JedisLockFactory(jedisPool);
    }

    @Bean
    public JedisDistributedLockTemplate getTemplate() {
        JedisDistributedLockTemplate lockTemplate = new JedisDistributedLockTemplate();
        lockTemplate.setJedisLockFactory(jedisLockFactory);

        return lockTemplate;
    }
}
